home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / uwin / cassette / mainfrm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  7.2 KB  |  253 lines

  1. // Copyright (c) 1994, William Wagner.
  2. // All Rights reserved.
  3. //
  4. // This source is a portion of a shareware program.  It may be distributed
  5. // only in its entirety.  The copyright statements must be included with any 
  6. // reproduction of this source.
  7. // 
  8. // mainfrm.cpp : implementation of the CMainFrame class
  9. //
  10.  
  11. #include "stdafx.h"
  12. #include "cassette.h"
  13.  
  14. #include "mainfrm.h"
  15. #include "printvie.h"
  16. #include "tapeview.h"
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char BASED_CODE THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. //Constants used for sizes of the views
  24. static const int DLG_X = 4;
  25. static const int DLG_Y = 8;
  26.  
  27. static const int VIEW_X = 130;
  28. static const int VIEW_Y = 480;
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CMainFrame
  32.  
  33. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  34.  
  35. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  36.     //{{AFX_MSG_MAP(CMainFrame)
  37.     ON_WM_CREATE()
  38.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
  39.     ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
  40.     //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42.  
  43. /////////////////////////////////////////////////////////////////////////////
  44. // arrays of IDs used to initialize control bars
  45.  
  46. // toolbar buttons - IDs are command buttons
  47. // I double the separators.  I think it looks better.
  48. static UINT BASED_CODE buttons[] =
  49. {
  50.     // same order as in the bitmap 'toolbar.bmp'
  51.     ID_FILE_NEW,
  52.     ID_FILE_OPEN,
  53.     ID_FILE_SAVE,
  54.         ID_SEPARATOR,
  55.         ID_SEPARATOR,
  56.     ID_FILE_PRINT,
  57.         ID_SEPARATOR,
  58.         ID_SEPARATOR,
  59.     ID_APP_ABOUT,
  60.     ID_CONTEXT_HELP,
  61. };
  62.  
  63. static UINT BASED_CODE indicators[] =
  64. {
  65.     ID_SEPARATOR,            // status line indicator
  66.     ID_INDICATOR_CAPS,
  67.     ID_INDICATOR_NUM,
  68.     ID_INDICATOR_SCRL,
  69. };
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. // CMainFrame construction/destruction
  73.  
  74. // Constructor.
  75. // This is an empty constructor.  Not much happens in the construction
  76. // of this class.  
  77. //
  78. // I am purposefully trying to keep this a very small class.  I may
  79. // change this to an MDI application.  Therefore, I am trying to keep as
  80. // little as possible here.
  81. // Dont call ASSERT_VALID because the splitter is not yet all there.
  82. CMainFrame::CMainFrame()
  83. {
  84. }
  85.  
  86. // Destructor.
  87. // This too is empty.  It needs to exist because of base classes that 
  88. // have virtual destructors.
  89. CMainFrame::~CMainFrame()
  90. {
  91. ASSERT_VALID (this);
  92. }
  93.  
  94. // This function is called during the processing of the WM_CREATE
  95. // message.  Its function is to creates the non-client area controls.
  96. // Those are the toolbar and the status bar.  
  97. // Those controls cannot be created during the constructor, because the
  98. // window resource has not been created.  This overrides the base class
  99. // implementation, which must be called from this function.
  100. // Dont call ASSERT_VALID because the splitter is not yet all there.
  101. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  102. {
  103. int retval;
  104.  
  105. if (-1 == CFrameWnd::OnCreate(lpCreateStruct))
  106.     retval = -1;
  107. else if (!m_wndToolBar.Create(this) ||
  108.     !m_wndToolBar.LoadBitmap(IDR_MAINFRAME) ||
  109.     !m_wndToolBar.SetButtons(buttons,
  110.     sizeof(buttons)/sizeof(UINT)))
  111.     {
  112.     TRACE("Failed to create toolbar\n");
  113.     retval = -1;
  114.     }
  115. else if (!m_wndStatusBar.Create(this) ||
  116.     !m_wndStatusBar.SetIndicators(indicators,
  117.     sizeof(indicators)/sizeof(UINT)))
  118.     {
  119.     TRACE("Failed to create status bar\n");
  120.     retval = -1;
  121.     }
  122. else
  123.     retval = 0;
  124.  
  125. ASSERT (0 == retval);
  126.  
  127. return retval;
  128. }
  129.  
  130. // This function is called during the creation of the client window.  The default
  131. // implementaion creates a single view class client window.  This application needs
  132. // more extensive services.  Therefore, it creates the splitter window, and creates
  133. // the two views that make up the splitter window views.
  134. // Dont call ASSERT_VALID until the end because the splitter is not yet all there.
  135. BOOL CMainFrame::OnCreateClient ( LPCREATESTRUCT /* lpCreateStruct */, CCreateContext* pContext)
  136. {
  137. BOOL retval;
  138. DWORD dlgUnit = GetDialogBaseUnits ();
  139. CSize ViewSize ((VIEW_X* LOWORD (dlgUnit)) / DLG_X, (VIEW_Y * HIWORD (dlgUnit)) / DLG_Y);
  140.  
  141. if (!m_wndSplitter.CreateStatic (this, 1, 2))
  142.     retval = FALSE;
  143. else if (!m_wndSplitter.CreateView (0,0, RUNTIME_CLASS (CTapeView), ViewSize, pContext))
  144.     retval = FALSE;
  145. else if (!m_wndSplitter.CreateView (0,1, RUNTIME_CLASS (CPrintView), ViewSize, pContext))
  146.     retval =  FALSE;
  147. else
  148.     retval = TRUE;
  149.     
  150. ASSERT (TRUE == retval);
  151. ASSERT_VALID (this);
  152.  
  153. return retval;
  154. }
  155.  
  156. // This utility function returns a pointer to the print view.  
  157. // The print view is the right pane: row 0, column 1.  
  158. // This function returns the pointer to the correct view.
  159. CPrintView* CMainFrame::GetPrintView ()
  160. {
  161. ASSERT_VALID (this);
  162. ASSERT (2 == m_wndSplitter.GetColumnCount ());
  163. ASSERT (1 == m_wndSplitter.GetRowCount ());
  164.  
  165. CWnd* pPrintView = m_wndSplitter.GetPane (0,1);
  166.  
  167. ASSERT_VALID (pPrintView);
  168. ASSERT(pPrintView->IsKindOf(RUNTIME_CLASS(CPrintView)));
  169.  
  170. return (CPrintView*) pPrintView;
  171. }
  172.  
  173. // This utility function returns a pointer to the tape form view.  
  174. // The tape form view is the left pane: row 0, column 0.  
  175. // This function returns the pointer to the correct view.
  176. CTapeView* CMainFrame::GetTapeView ()
  177. {
  178. ASSERT_VALID (this);
  179. ASSERT (2 == m_wndSplitter.GetColumnCount ());
  180. ASSERT (1 == m_wndSplitter.GetRowCount ());
  181.  
  182. CWnd* pTapeView = m_wndSplitter.GetPane (0,0);
  183.  
  184. ASSERT_VALID (pTapeView);
  185. ASSERT(pTapeView->IsKindOf(RUNTIME_CLASS(CTapeView)));
  186.  
  187. return (CTapeView*) pTapeView;
  188. }
  189.  
  190. /////////////////////////////////////////////////////////////////////////////
  191. // CMainFrame diagnostics
  192.  
  193. #ifdef _DEBUG
  194. // Validation routine.
  195. // This tests the validity of the main frame object. The member objects
  196. // are validated.  However, objects pointed to are not validated.  
  197. void CMainFrame::AssertValid() const
  198. {
  199. CFrameWnd::AssertValid();
  200. m_wndSplitter.AssertValid ();
  201. m_wndToolBar.AssertValid ();
  202. m_wndStatusBar.AssertValid ();
  203. }
  204.  
  205. void CMainFrame::Dump(CDumpContext& dc) const
  206. {
  207. CFrameWnd::Dump(dc);
  208. m_wndSplitter.Dump (dc);
  209. m_wndToolBar.Dump (dc);
  210. m_wndStatusBar.Dump (dc);
  211. }
  212. #endif //_DEBUG
  213.  
  214. /////////////////////////////////////////////////////////////////////////////
  215. // CMainFrame message handlers
  216.  
  217. // You will note that these two functions look almost exactly the same.
  218. // This is by design.  The CFormView classes do not cope well (or at all)
  219. // with the print and print preview functions.  So...
  220. // if these to commands get here, we secretly switch the active view to
  221. // the print view.  Then call its command handler.  Finally, restore the 
  222. // active view back.
  223. // The debug version checks that the tape view was active.  (this avoids
  224. // any infinite loops.)
  225. void CMainFrame::OnFilePrintPreview()
  226. {
  227. ASSERT_VALID (this);
  228.  
  229. CView* pOldView = GetActiveView ();
  230. ASSERT(pOldView->IsKindOf(RUNTIME_CLASS(CTapeView)));
  231.  
  232. SetActiveView (GetPrintView ());
  233. GetPrintView ()->OnFilePrintPreview ();
  234. SetActiveView (pOldView);
  235.  
  236. ASSERT_VALID (this);
  237. }
  238.  
  239. // See OnFilePrintPreview (up about 10 lines).
  240. void CMainFrame::OnFilePrint()
  241. {
  242. ASSERT_VALID (this);
  243.  
  244. CView* pOldView = GetActiveView ();
  245. ASSERT(pOldView->IsKindOf(RUNTIME_CLASS(CTapeView)));
  246.  
  247. SetActiveView (GetPrintView ());
  248. GetPrintView ()->OnFilePrint ();
  249. SetActiveView (pOldView);
  250.  
  251. ASSERT_VALID (this);
  252. }
  253.